package main.java.com.healthy.entity;

import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 健康建议实体类
 * 对应功能模块：智能饮食建议模块
 */
public class HealthAdvice implements Serializable {
    private static final long serialVersionUID = 1L;

    private String adviceId;
    private String userId;
    private String adviceType; // 建议类型：营养均衡、热量控制、食物选择、饮食习惯、运动建议
    private String title; // 建议标题
    private String content; // 建议内容
    private String priority; // 优先级：高、中、低
    private String nutrientFocus; // 关注的营养素
    private LocalDate generateDate;
    private LocalDateTime createTime;
    private boolean isRead; // 是否已读
    private boolean isImplemented; // 是否已实施
    private String feedback; // 用户反馈

    // 默认构造方法
    public HealthAdvice() {
        this.generateDate = LocalDate.now();
        this.createTime = LocalDateTime.now();
        this.isRead = false;
        this.isImplemented = false;
        this.priority = "中";
    }

    // 主要参数构造方法
    public HealthAdvice(String adviceId, String userId, String adviceType,
                        String title, String content, String priority) {
        this();
        this.adviceId = adviceId;
        this.userId = userId;
        this.adviceType = adviceType;
        this.title = title;
        this.content = content;
        this.priority = priority;
    }

    // Getter和Setter方法
    public String getAdviceId() {
        return adviceId;
    }

    public void setAdviceId(String adviceId) {
        this.adviceId = adviceId;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getAdviceType() {
        return adviceType;
    }

    public void setAdviceType(String adviceType) {
        this.adviceType = adviceType;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getPriority() {
        return priority;
    }

    public void setPriority(String priority) {
        this.priority = priority;
    }

    public String getNutrientFocus() {
        return nutrientFocus;
    }

    public void setNutrientFocus(String nutrientFocus) {
        this.nutrientFocus = nutrientFocus;
    }

    public LocalDate getGenerateDate() {
        return generateDate;
    }

    public void setGenerateDate(LocalDate generateDate) {
        this.generateDate = generateDate;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public boolean isRead() {
        return isRead;
    }

    public void setRead(boolean read) {
        isRead = read;
    }

    public boolean isImplemented() {
        return isImplemented;
    }

    public void setImplemented(boolean implemented) {
        isImplemented = implemented;
    }

    public String getFeedback() {
        return feedback;
    }

    public void setFeedback(String feedback) {
        this.feedback = feedback;
    }

    // 获取优先级代码（用于排序）
    public int getPriorityCode() {
        switch (priority) {
            case "高": return 1;
            case "中": return 2;
            case "低": return 3;
            default: return 2;
        }
    }

    // 标记为已读
    public void markAsRead() {
        this.isRead = true;
    }

    // 标记为已实施
    public void markAsImplemented() {
        this.isImplemented = true;
    }

    // 获取建议摘要（前50个字符）
    public String getSummary() {
        if (content == null) return "";
        return content.length() > 50 ? content.substring(0, 50) + "..." : content;
    }

    // 检查建议是否过期（生成超过30天）
    public boolean isExpired() {
        return generateDate.isBefore(LocalDate.now().minusDays(30));
    }

    @Override
    public String toString() {
        return "HealthAdvice{" +
                "adviceId='" + adviceId + '\'' +
                ", userId='" + userId + '\'' +
                ", adviceType='" + adviceType + '\'' +
                ", title='" + title + '\'' +
                ", priority='" + priority + '\'' +
                ", generateDate=" + generateDate +
                ", isRead=" + isRead +
                ", isImplemented=" + isImplemented +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        HealthAdvice that = (HealthAdvice) o;
        return adviceId.equals(that.adviceId);
    }

    @Override
    public int hashCode() {
        return adviceId.hashCode();
    }
}
